﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Wp.DAL;

namespace Wp.BLL
{
    /// <summary>
    /// Summary description for TblTermTaxonomy
    /// </summary>
    public class TblTermTaxonomyManagerBase
    {
        public TblTermTaxonomyManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int InsertUpdate(TblTermTaxonomyEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@Output", item.Id);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@TermId", item.TermId));
            ls.Add(new SqlParameter("@Taxonomy", item.Taxonomy));
            ls.Add(new SqlParameter("@Description", item.Description));
            ls.Add(new SqlParameter("@ParentId", item.ParentId));
            ls.Add(new SqlParameter("@Count", item.Count));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_InsertUpdateTblTermTaxonomy", sqlparam);
            return int.Parse(sqlparam[0].Value.ToString());
        }
        public int InsertUpdate(int Id, int TermId, string Taxonomy, string Description, int ParentId, int Count)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@Output", Id);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@TermId", TermId));
            ls.Add(new SqlParameter("@Taxonomy", Taxonomy));
            ls.Add(new SqlParameter("@Description", Description));
            ls.Add(new SqlParameter("@ParentId", ParentId));
            ls.Add(new SqlParameter("@Count", Count));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_InsertUpdateTblTermTaxonomy", sqlparam);
            return int.Parse(sqlparam[0].Value.ToString());
        }
        public void Delete(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_DeleteTblTermTaxonomy", sqlparam);
        }

        public DataTable SelectOneRDT(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return SqlHelper.ExecuteDataTable(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_SelectTblTermTaxonomy", sqlparam);
        }
        public TblTermTaxonomyEntity SelectOne(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_SelectTblTermTaxonomy", sqlparam);
            if (dt != null && dt.Rows.Count > 0)
                return TblTermTaxonomyEntity.CreateInstant().GetTblTermTaxonomyEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return SqlHelper.ExecuteDataTable(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_SelectTblTermTaxonomiesAll", null);
        }
        public List<TblTermTaxonomyEntity> SelectAll()
        {
            List<TblTermTaxonomyEntity> lsresult = new List<TblTermTaxonomyEntity>();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.WpConnectString, CommandType.StoredProcedure, "wp_SelectTblTermTaxonomiesAll", null);

            if (dt != null && dt.Rows.Count > 0)
            {
                TblTermTaxonomyEntity item = TblTermTaxonomyEntity.CreateInstant();
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(item.GetTblTermTaxonomyEntity(dt.Rows[i]));
            }
            return lsresult;
        }
    }
}

